﻿@page "/document/{Level?}"
@inject NavigationManager Navigation


<div style="display: flex; align-items: center; position: fixed; top: 0; left: 0; right: 0; height: 50px; background: rgb(254, 249, 231); box-shadow: 0 0 10px rgb(254, 249, 231); padding: 0 15px; z-index: 1">
    @if (Level != null)
    {
        <p>
            <span><b><a href="./document">NOI Exam Study文档</a></b></span>
            @if (Directory.Exists("./document/" + Level))
            {
                <span>  | <a>@(File.ReadAllText("./document/" + Level + "/DirectoryName.txt"))</a></span>
            }
            else
            {
                <span> | 未知目录</span>
            }
        </p>
    }
    else
    {
        <b>NOI Exam Study文档</b>
    }
</div>

<div style="padding: 15px; margin-top: 50px">
    @if (Level == null)
    {
        @foreach (string Floder in Directory.GetDirectories("./document"))
        {
            <button style="display: block; width: 100%; text-align: left; margin-bottom: 15px" @onclick='() => Navigation.NavigateTo("./document/" + Floder.Replace("\\", "/").Split("/").Last<string>())'>@(File.ReadAllText(Floder + "/DirectoryName.txt"))</button>
        }
    }
    else
    {
        if (Directory.Exists("./document/" + Level))
        {
            @foreach (string Document in Directory.GetFiles("./document/" + Level + "/", "*.md"))
            {
               <button style="display: block; width: 100%; text-align: left; margin-bottom: 15px" @onclick='() => Navigation.NavigateTo("./document/" + Level + "/" + Path.GetFileNameWithoutExtension(Document))'>@(File.ReadAllText("./document/" + Level + "/" + Path.GetFileNameWithoutExtension(Document) + ".txt"))</button>
            }
        }
        else
        {
            <div style="display: flex; align-content: center; align-items: center; justify-content: center; position: absolute; top: 50px; left: 0; right: 0; bottom: 0; padding: 15%">
                <h2>你所查找的目录不存在</h2>
            </div>
        }
    }
</div>

@functions
{
    [Parameter] public string? Level { get; set; }
}
